package gew.system;

import gew.metadata.Queries;
import gew.services.DimensionValueService;
import gew.services.LocaleService;
import gew.utils.SqlUtils;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.servlet.http.HttpServletRequest;

public class RequestParameter {

    public static final String PARENT_ROOT = "0";

    private static final String BUNDLE_NAME = "labels";
    private final Locale locale;
    private final String localeUrlCode;
    private final String serverName;
    private final int serverPort;
    private final String contextPath;
    private final String countryUrlCode;
    private final String[] countryUrlCodes;
    private final List<Integer> countryIds;
    private String countryIdsHS = null;
    private final String searchSectionUrlCode;
    private final String[] searchSectionUrlCodes;
    private final List<Integer> searchSectionIds;
    private String searchSectionIdsHS = null;
    private final String indicatorUrlCode;
    private final String[] indicatorUrlCodes;
    private final List<Integer> indicatorIds;
    private String indicatorIdsHS = null;
    private final String reporterUrlCode;
    private final boolean reporterUrlCodeIsDefault;
    private final String[] reporterUrlCodes;
    private final List<Integer> reporterIds;
    private String reporterIdsHS = null;
    private final String partnerUrlCode;
    private final String[] partnerUrlCodes;
    private final List<Integer> partnerIds;
    private String partnerIdsHS = null;
    private final String tradeFlowUrlCode;
    private final String[] tradeFlowUrlCodes;
    private final List<Integer> tradeFlowIds;
    private String tradeFlowIdsHS = null;
    private final String commodityGroupTypeUrlCode;
    private final String[] commodityGroupTypeUrlCodes;
    private final List<Integer> commodityGroupTypeIds;
    private String commodityGroupTypeIdsHS = null;
    private final String periodUrlCode;
    private final String[] periodUrlCodes;
    private final List<Integer> periodIds;
    private String periodIdsHS = null;
    private final String commodityUrlCode;
    private final String[] commodityUrlCodes;
    private final List<Integer> commodityIds;
    private String commodityIdsHS = null;
    private final String filterCode;
    private final String filterRequestType;
    private final String urlTemplate;
    private final String selectedIdsCS;
    private final String parentIdCS;
    private final boolean loadTableData;
    private int partnerRank;
    private String filterText;
    private String section;
    private DecimalFormat numberFormat;
    private DecimalFormat percentFormat;
    private final String requestURI;

    public RequestParameter(HttpServletRequest request, DimensionValueService dvs) {
        serverName = request.getServerName();
        serverPort = request.getServerPort();
        contextPath = request.getContextPath();

        Enumeration<String> pEnum = request.getAttributeNames();
        ArrayList<String> params = new ArrayList<>();
        while (pEnum.hasMoreElements()) {
            params.add(pEnum.nextElement());
        }

        if (request.getParameterMap().containsKey(Parameters.REQUEST_URI)) {
            requestURI = request.getParameterMap().get(Parameters.REQUEST_URI)[0];
        } else if (params.contains(Parameters.REQUEST_URI)) {
            requestURI = request.getAttribute(Parameters.REQUEST_URI).toString();
        } else {
            requestURI = "not specified";
        }

        if (request.getParameterMap().containsKey(Parameters.SECTION)) {
            section = request.getParameterMap().get(Parameters.SECTION)[0];
        } else if (params.contains(Parameters.SECTION)) {
            section = request.getAttribute(Parameters.SECTION).toString();
        } else {
            section = "not specified";
        }

        if (request.getParameterMap().containsKey(Parameters.LOCALE)) {
            localeUrlCode = LocaleService.getLocaleCode(request.getParameterMap().get(Parameters.LOCALE)[0]);
        } else if (params.contains(Parameters.LOCALE)) {
            localeUrlCode = LocaleService.getLocaleCode(request.getAttribute(Parameters.LOCALE).toString());
        } else {
            localeUrlCode = LocaleService.EN;
        }
        locale = LocaleService.getLocale(localeUrlCode);

        if (request.getParameterMap().containsKey(Parameters.COUNTRY)) {
            countryUrlCode = request.getParameterMap().get(Parameters.COUNTRY)[0];
        } else if (params.contains(Parameters.COUNTRY)) {
            countryUrlCode = request.getAttribute(Parameters.COUNTRY).toString();
        } else {
            countryUrlCode = ResourceBundle.getBundle(BUNDLE_NAME, locale).getString(LabelCode.PARAM_DEFAULT_COUNTRY_CODE_VALUE);
        }
        countryUrlCodes = countryUrlCode.split(SqlUtils.HYPHEN);
        if (request.getParameterMap().containsKey(Parameters.COUNTRY_IDs)) {
            countryIds = getAsListOfInteger(request.getParameterMap().get(Parameters.COUNTRY_IDs)[0]);
        } else {
            countryIds = dvs.getIdByUrlCode(locale, countryUrlCode, Queries.CountryDimensionValue);
        }

        if (request.getParameterMap().containsKey(Parameters.SEARCH_SECTIONS)) {
            searchSectionUrlCode = request.getParameterMap().get(Parameters.SEARCH_SECTIONS)[0];
        } else if (params.contains(Parameters.SEARCH_SECTIONS)) {
            searchSectionUrlCode = request.getAttribute(Parameters.SEARCH_SECTIONS).toString();
        } else {
            searchSectionUrlCode = ResourceBundle.getBundle(BUNDLE_NAME, locale).getString(LabelCode.PARAM_DEFAULT_SEARCH_SECTION);
        }
        searchSectionUrlCodes = searchSectionUrlCode.split(SqlUtils.HYPHEN);
        searchSectionIds = dvs.getIdByUrlCode(locale, searchSectionUrlCode, Queries.SectionDimensionValue);

        if (request.getParameterMap().containsKey(Parameters.INDICATOR)) {
            indicatorUrlCode = request.getParameterMap().get(Parameters.INDICATOR)[0];
        } else if (params.contains(Parameters.INDICATOR)) {
            indicatorUrlCode = request.getAttribute(Parameters.INDICATOR).toString();
        } else {
            indicatorUrlCode = ResourceBundle.getBundle(BUNDLE_NAME, locale).getString(LabelCode.PARAM_DEFAULT_INDICATOR_CODE_VALUE);
        }
        indicatorUrlCodes = indicatorUrlCode.split(SqlUtils.HYPHEN);
        if (request.getParameterMap().containsKey(Parameters.INDICATOR_IDs)) {
            indicatorIds = getAsListOfInteger(request.getParameterMap().get(Parameters.INDICATOR_IDs)[0]);
        } else {
            indicatorIds = dvs.getIdByUrlCode(locale, indicatorUrlCode, Queries.IndicatorDimensionValue);
        }

        if (request.getParameterMap().containsKey(Parameters.REPORTER)) {
            reporterUrlCode = request.getParameterMap().get(Parameters.REPORTER)[0];
            reporterUrlCodeIsDefault = false;
        } else if (params.contains(Parameters.REPORTER)) {
            reporterUrlCode = request.getAttribute(Parameters.REPORTER).toString();
            reporterUrlCodeIsDefault = false;
        } else {
            reporterUrlCode = ResourceBundle.getBundle(BUNDLE_NAME, locale).getString(LabelCode.PARAM_DEFAULT_REPORTER_CODE_VALUE);
            reporterUrlCodeIsDefault = true;
        }
        reporterUrlCodes = reporterUrlCode.split(SqlUtils.HYPHEN);
        if (request.getParameterMap().containsKey(Parameters.REPORTER_IDS)) {
            reporterIds = getAsListOfInteger(request.getParameterMap().get(Parameters.REPORTER_IDS)[0]);
        } else {
            reporterIds = dvs.getIdByUrlCode(locale, reporterUrlCode, Queries.CountryDimensionValue);
        }

        if (request.getParameterMap().containsKey(Parameters.PARTNER)) {
            partnerUrlCode = request.getParameterMap().get(Parameters.PARTNER)[0];
        } else if (params.contains(Parameters.PARTNER)) {
            partnerUrlCode = request.getAttribute(Parameters.PARTNER).toString();
        } else {
            partnerUrlCode = ResourceBundle.getBundle(BUNDLE_NAME, locale).getString(LabelCode.PARAM_DEFAULT_PARTNER_CODE_VALUE);
        }
        partnerUrlCodes = partnerUrlCode.split(SqlUtils.HYPHEN);
        if (request.getParameterMap().containsKey(Parameters.PARTNER_IDS)) {
            partnerIds = getAsListOfInteger(request.getParameterMap().get(Parameters.PARTNER_IDS)[0]);
        } else {
            partnerIds = dvs.getIdByUrlCode(locale, partnerUrlCode, Queries.CountryDimensionValue);
        }

        if (request.getParameterMap().containsKey(Parameters.TRADE_FLOW)) {
            tradeFlowUrlCode = request.getParameterMap().get(Parameters.TRADE_FLOW)[0];
        } else if (params.contains(Parameters.TRADE_FLOW)) {
            tradeFlowUrlCode = request.getAttribute(Parameters.TRADE_FLOW).toString();
        } else {
            tradeFlowUrlCode = ResourceBundle.getBundle(BUNDLE_NAME, locale).getString(LabelCode.PARAM_DEFAULT_TRADE_FLOW_CODE_VALUE);
        }
        tradeFlowUrlCodes = tradeFlowUrlCode.split(SqlUtils.HYPHEN);
        if (request.getParameterMap().containsKey(Parameters.TRADE_FLOW_IDS)) {
            tradeFlowIds = getAsListOfInteger(request.getParameterMap().get(Parameters.TRADE_FLOW_IDS)[0]);
        } else {
            tradeFlowIds = dvs.getIdByUrlCode(locale, tradeFlowUrlCode, Queries.TradeFlowDimensionValue);
        }

        if (request.getParameterMap().containsKey(Parameters.PERIOD)) {
            periodUrlCode = request.getParameterMap().get(Parameters.PERIOD)[0];
        } else if (params.contains(Parameters.PERIOD)) {
            periodUrlCode = request.getAttribute(Parameters.PERIOD).toString();
        } else {
            periodUrlCode = ResourceBundle.getBundle(BUNDLE_NAME, locale).getString(LabelCode.PARAM_DEFAULT_PERIOD_CODE_VALUE);
        }
        periodUrlCodes = periodUrlCode.split(SqlUtils.HYPHEN);
        if (request.getParameterMap().containsKey(Parameters.PERIOD_IDS)) {
            periodIds = getAsListOfInteger(request.getParameterMap().get(Parameters.PERIOD_IDS)[0]);
        } else {
            periodIds = dvs.getIdByUrlCode(locale, periodUrlCode, Queries.PeriodDimensionValue);
        }

        if (request.getParameterMap().containsKey(Parameters.COMMODITY_GROUP_TYPE)) {
            commodityGroupTypeUrlCode = request.getParameterMap().get(Parameters.COMMODITY_GROUP_TYPE)[0];
        } else if (params.contains(Parameters.COMMODITY_GROUP_TYPE)) {
            commodityGroupTypeUrlCode = request.getAttribute(Parameters.COMMODITY_GROUP_TYPE).toString();
        } else {
            commodityGroupTypeUrlCode = ResourceBundle.getBundle(BUNDLE_NAME, locale).getString(LabelCode.PARAM_DEFAULT_COMMODITY_GROUP_TYPE_CODE_VALUE);
        }
        commodityGroupTypeUrlCodes = commodityGroupTypeUrlCode.split(SqlUtils.HYPHEN);
        if (request.getParameterMap().containsKey(Parameters.COMMODITY_GROUP_TYPE_IDS)) {
            commodityGroupTypeIds = getAsListOfInteger(request.getParameterMap().get(Parameters.COMMODITY_GROUP_TYPE_IDS)[0]);
        } else {
            commodityGroupTypeIds = dvs.getIdByUrlCode(locale, commodityGroupTypeUrlCode, Queries.CommodityGroupTypeDimensionValue);
        }

        if (request.getParameterMap().containsKey(Parameters.COMMODITY)) {
            commodityUrlCode = request.getParameterMap().get(Parameters.COMMODITY)[0];
        } else if (params.contains(Parameters.COMMODITY)) {
            commodityUrlCode = request.getAttribute(Parameters.COMMODITY).toString();
        } else {
            if (commodityGroupTypeUrlCodes.length == 1) {
                commodityUrlCode = commodityGroupTypeUrlCodes[0].concat(SqlUtils.TOTAL);
            } else {
                commodityUrlCode = ResourceBundle.getBundle(BUNDLE_NAME, locale).getString(LabelCode.PARAM_DEFAULT_COMMODITY_CODE_VALUE);
            }
        }
        commodityUrlCodes = commodityUrlCode.split(SqlUtils.HYPHEN);
        if (request.getParameterMap().containsKey(Parameters.COMMODITY_IDS)) {
            commodityIds = getAsListOfInteger(request.getParameterMap().get(Parameters.COMMODITY_IDS)[0]);
        } else {
            commodityIds = dvs.getIdByUrlCode(locale, commodityUrlCode, Queries.CommodityDimensionValue);
        }

        if (request.getParameterMap().containsKey(Parameters.FILTER_CODE)) {
            filterCode = request.getParameterMap().get(Parameters.FILTER_CODE)[0];
        } else {
            filterCode = "";
        }

        if (request.getParameterMap().containsKey(Parameters.FILTER_REQUEST_TYPE)) {
            filterRequestType = request.getParameterMap().get(Parameters.FILTER_REQUEST_TYPE)[0];
        } else {
            filterRequestType = "";
        }

        if (request.getParameterMap().containsKey(Parameters.URL_TEMPLATE)) {
            urlTemplate = request.getParameterMap().get(Parameters.URL_TEMPLATE)[0];
        } else {
            urlTemplate = "";
        }

        if (request.getParameterMap().containsKey(Parameters.SELECTED_IDS)) {
            selectedIdsCS = request.getParameterMap().get(Parameters.SELECTED_IDS)[0];
        } else {
            selectedIdsCS = "";
        }

        if (request.getParameterMap().containsKey(Parameters.PARENT_ID)) {
            parentIdCS = request.getParameterMap().get(Parameters.PARENT_ID)[0];
        } else {
            parentIdCS = PARENT_ROOT;
        }

        if (request.getParameterMap().containsKey(Parameters.PARTNER_RANK)) {
            try {
                partnerRank = Integer.parseInt(request.getParameterMap().get(Parameters.PARTNER_RANK)[0]);
            } catch (NumberFormatException e) {
                partnerRank = 5;
            }
        } else {
            partnerRank = 5;
        }

        if (request.getParameterMap().containsKey(Parameters.FILTER_TEXT)) {
            try {
                filterText = request.getParameterMap().get(Parameters.FILTER_TEXT)[0];
                filterText = filterText
                        .replace("--", SqlUtils.EMPTY)
                        .replace("*", SqlUtils.EMPTY)
                        .replace("'", SqlUtils.EMPTY)
                        .replace("/", SqlUtils.EMPTY)
                        .replace("\\", SqlUtils.EMPTY);
                String[] words = filterText.split(SqlUtils.SPACE);
                filterText = "";
                for (int i = 0; i < words.length; i++) {
                    if (words[i].trim().length() > 2) {
                        filterText = filterText.concat(SqlUtils.SPACE).concat(words[i].trim());
                    }
                }
            } catch (NumberFormatException e) {
                filterText = SqlUtils.EMPTY;
            }
        } else {
            filterText = "";
        }

        if (request.getParameterMap().containsKey(Parameters.LOAD_TABLE_DATA)) {
            loadTableData = "1".equals(request.getParameterMap().get(Parameters.LOAD_TABLE_DATA)[0]);
        } else {
            loadTableData = false;
        }
    }

    private List<Integer> getAsListOfInteger(String commaSeparatedIds) {
        List<Integer> result = new ArrayList();
        String[] ids = commaSeparatedIds.split(SqlUtils.COMMA);
        for (Integer i = 0; i < ids.length; i++) {
            try {
                result.add(Integer.parseInt(ids[i]));
            } catch (Exception e) {
            }
        }
        return result;
    }

    public DecimalFormat getNumberFormat() {
        if (numberFormat == null) {
            numberFormat = new DecimalFormat();
            DecimalFormatSymbols decFS = new DecimalFormatSymbols();
            decFS.setDecimalSeparator(LocaleService.getDecimalSeparator(locale));
            decFS.setGroupingSeparator(LocaleService.getGroupingSeparator(locale));
            numberFormat.setGroupingSize(3);
            numberFormat.setGroupingUsed(true);
            numberFormat.setDecimalFormatSymbols(decFS);
        }
        return numberFormat;
    }

    public DecimalFormat getPercentFormat() {
        if (percentFormat == null) {
            percentFormat = new DecimalFormat();
            DecimalFormatSymbols decFS = new DecimalFormatSymbols();
            decFS.setDecimalSeparator(LocaleService.getDecimalSeparator(locale));
            decFS.setGroupingSeparator(LocaleService.getGroupingSeparator(locale));
            percentFormat.setGroupingSize(3);
            percentFormat.setGroupingUsed(true);
            percentFormat.setDecimalFormatSymbols(decFS);
            percentFormat.setMinimumFractionDigits(2);
        }
        return percentFormat;
    }

    @Override
    public String toString() {
        StringBuilder buf = new StringBuilder();

        buf.append(Parameters.LOCALE).append(SqlUtils.EQUALS).append(getLocaleUrlCode());
        buf.append(SqlUtils.AMPERSAND);
        buf.append(Parameters.COUNTRY).append(SqlUtils.EQUALS).append(getCountryUrlCode());
        buf.append(SqlUtils.AMPERSAND);
        buf.append(Parameters.COUNTRY_IDs).append(SqlUtils.EQUALS).append(getCountryIdsCS());
        buf.append(SqlUtils.AMPERSAND);
        buf.append(Parameters.REPORTER).append(SqlUtils.EQUALS).append(getReporterUrlCode());
        buf.append(SqlUtils.AMPERSAND);
        buf.append(Parameters.REPORTER_IDS).append(SqlUtils.EQUALS).append(getReporterIdsCS());
        buf.append(SqlUtils.AMPERSAND);
        buf.append(Parameters.PARTNER).append(SqlUtils.EQUALS).append(getPartnerUrlCode());
        buf.append(SqlUtils.AMPERSAND);
        buf.append(Parameters.PARTNER_IDS).append(SqlUtils.EQUALS).append(getPartnerIdsCS());
        buf.append(SqlUtils.AMPERSAND);
        buf.append(Parameters.TRADE_FLOW).append(SqlUtils.EQUALS).append(getTradeFlowUrlCode());
        buf.append(SqlUtils.AMPERSAND);
        buf.append(Parameters.TRADE_FLOW_IDS).append(SqlUtils.EQUALS).append(getTradeFlowIdsCS());
        buf.append(SqlUtils.AMPERSAND);
        buf.append(Parameters.COMMODITY_GROUP_TYPE).append(SqlUtils.EQUALS).append(getCommodityGroupTypeUrlCode());
        buf.append(SqlUtils.AMPERSAND);
        buf.append(Parameters.COMMODITY_GROUP_TYPE_IDS).append(SqlUtils.EQUALS).append(getCommodityGroupTypeIdsCS());
        buf.append(SqlUtils.AMPERSAND);
        buf.append(Parameters.COMMODITY).append(SqlUtils.EQUALS).append(getCommodityUrlCode());
        buf.append(SqlUtils.AMPERSAND);
        buf.append(Parameters.COMMODITY_IDS).append(SqlUtils.EQUALS).append(getCommodityIdsCS());

        return buf.toString();
    }

    public Locale getLocale() {
        return locale;
    }

    public String getSection() {
        return section;
    }

    public List<Integer> getCountryIds() {
        return countryIds;
    }

    public String getCountryIdsCS() {
        return getIdsCS(countryIds);
    }

    public String getCountryUrlCode() {
        return countryUrlCode;
    }

    public String getCountryUrlCodeCS() {
        return getCodesCS(countryUrlCodes);
    }

    public String getCountryUrlCodeCSDoubleQuoted() {
        return getCodesCSDoubleQuoted(countryUrlCodes);
    }

    public List<Integer> getIndicatorIds() {
        return indicatorIds;
    }

    public String getIndicatorIdsCS() {
        return getIdsCS(indicatorIds);
    }

    private static String getIdsHS(List<Integer> ids) {
        String r = "";
        for (int i = 0; i < ids.size(); i++) {
            r = i == 0
                    ? ids.get(i).toString()
                    : r.concat(SqlUtils.COMMA)
                    .concat(ids.get(i).toString());
        }
        return r;
    }

    public String getIndicatorIdsHS() {
        if (indicatorIdsHS == null) {
            indicatorIdsHS = getIdsHS(indicatorIds);
        }
        return indicatorIdsHS;
    }

    public String getCountryIdsHS() {
        if (countryIdsHS == null) {
            countryIdsHS = getIdsHS(countryIds);
        }
        return countryIdsHS;
    }

    public String getSearchSectionIdsHS() {
        if (searchSectionIdsHS == null) {
            searchSectionIdsHS = getIdsHS(searchSectionIds);
        }
        return searchSectionIdsHS;
    }

    public String getReporterIdsHS() {
        if (reporterIdsHS == null) {
            reporterIdsHS = getIdsHS(reporterIds);
        }
        return reporterIdsHS;
    }

    public String getTradeFlowIdsHS() {
        if (tradeFlowIdsHS == null) {
            tradeFlowIdsHS = getIdsHS(tradeFlowIds);
        }
        return tradeFlowIdsHS;
    }

    public String getPartnerIdsHS() {
        if (partnerIdsHS == null) {
            partnerIdsHS = getIdsHS(partnerIds);
        }
        return partnerIdsHS;
    }

    public String getPeriodIdsHS() {
        if (periodIdsHS == null) {
            periodIdsHS = getIdsHS(periodIds);
        }
        return periodIdsHS;
    }

    public String getCommodityGroupTypeIdsHS() {
        if (commodityGroupTypeIdsHS == null) {
            commodityGroupTypeIdsHS = getIdsHS(commodityGroupTypeIds);
        }
        return commodityGroupTypeIdsHS;
    }

    public String getCommodityIdsHS() {
        if (commodityIdsHS == null) {
            commodityIdsHS = getIdsHS(commodityIds);
        }
        return commodityIdsHS;
    }

    public String getIndicatorUrlCode() {
        return indicatorUrlCode;
    }

    public String getIndicatorUrlCodeCS() {
        return getCodesCS(indicatorUrlCodes);
    }

    public String getIndicatorUrlCodeCSDoubleQuoted() {
        return getCodesCSDoubleQuoted(indicatorUrlCodes);
    }

    public String getServerName() {
        return serverName;
    }

    public Integer getServerPort() {
        return serverPort;
    }

    public String getHttpHeader() {
        return serverPort == 80
                ? SqlUtils.HTTP.concat(this.serverName)
                : SqlUtils.HTTP.concat(this.serverName)
                .concat(SqlUtils.COLON)
                .concat(getServerPort().toString());
    }

    public String getContextPath() {
        return contextPath;
    }

    public String getReporterUrlCode() {
        return reporterUrlCode;
    }

    public List<Integer> getReporterIds() {
        return reporterIds;
    }

    public String getReporterIdsCS() {
        return getIdsCS(reporterIds);
    }

    public String[] getReporterUrlCodes() {
        return reporterUrlCodes;
    }

    public String getReporterUrlCodeCS() {
        return getCodesCS(reporterUrlCodes);
    }

    public String getReporterUrlCodeCSDoubleQuoted() {
        return getCodesCSDoubleQuoted(reporterUrlCodes);
    }

    public String getPartnerUrlCode() {
        return partnerUrlCode;
    }

    public List<Integer> getPartnerIds() {
        return partnerIds;
    }

    public String getPartnerIdsCS() {
        return getIdsCS(partnerIds);
    }

    public String getPartnerUrlCodeCS() {
        return getCodesCS(partnerUrlCodes);
    }

    public String getPartnerUrlCodeCSDoubleQuoted() {
        return getCodesCSDoubleQuoted(partnerUrlCodes);
    }

    public String getTradeFlowUrlCode() {
        return tradeFlowUrlCode;
    }

    public List<Integer> getTradeFlowIds() {
        return tradeFlowIds;
    }

    public String getTradeFlowIdsCS() {
        return getIdsCS(tradeFlowIds);
    }

    public String getTradeFlowUrlCodeCS() {
        return getCodesCS(tradeFlowUrlCodes);
    }

    public String getTradeFlowUrlCodeCSDoubleQuoted() {
        return getCodesCSDoubleQuoted(tradeFlowUrlCodes);
    }

    public String getPeriodIdsCS() {
        return getIdsCS(periodIds);
    }

    public String getPeriodUrlCodeCS() {
        return getCodesCS(periodUrlCodes);
    }

    public String getPeriodUrlCodeCSDoubleQuoted() {
        return getCodesCSDoubleQuoted(periodUrlCodes);
    }

    public String getCommodityGroupTypeIdsCS() {
        return getIdsCS(commodityGroupTypeIds);
    }

    public String getCommodityIdsCS() {
        return getIdsCS(commodityIds);
    }

    public String getLocaleUrlCode() {
        return localeUrlCode;
    }

    public String getCommodityGroupTypeUrlCode() {
        return commodityGroupTypeUrlCode;
    }

    public List<Integer> getCommodityGroupTypeIds() {
        return commodityGroupTypeIds;
    }

    public String getCommodityGroupTypeUrlCodeCS() {
        return getCodesCS(commodityGroupTypeUrlCodes);
    }

    public String getCommodityGroupTypeUrlCodeCSDoubleQuoted() {
        return getCodesCSDoubleQuoted(commodityGroupTypeUrlCodes);
    }

    public String getPeriodUrlCode() {
        return periodUrlCode;
    }

    public List<Integer> getPeriodIds() {
        return periodIds;
    }

    public String getCommodityUrlCode() {
        return commodityUrlCode;
    }

    public String getCommodityUrlCodeCS() {
        return getCodesCS(commodityUrlCodes);
    }

    public String getCommodityUrlCodeCSDoubleQuoted() {
        return getCodesCSDoubleQuoted(commodityUrlCodes);
    }

    public List<Integer> getCommodityIds() {
        return commodityIds;
    }

    public String getFilterCode() {
        return filterCode;
    }

    public String getSelectedIdsCS() {
        return selectedIdsCS;
    }

    public String getParentIdCS() {
        return parentIdCS;
    }

    public String getFilterText() {
        return filterText;
    }

    private String getIdsCS(List<Integer> ids) {
        String r = "";
        for (int i = 0; i < ids.size(); i++) {
            if (i > 0) {
                r = r.concat(SqlUtils.COMMA);
            }
            r = r.concat(ids.get(i).toString());
        }
        return r;
    }

    private String getCodesCS(String[] codes) {
        String r = "";
        for (int i = 0; i < codes.length; i++) {
            if (i > 0) {
                r = r.concat(SqlUtils.COMMA);
            }
            r = r.concat(codes[i]);
        }
        return r;
    }

    private String getCodesCSDoubleQuoted(String[] codes) {
        String r = "";
        for (int i = 0; i < codes.length; i++) {
            if (i > 0) {
                r = r.concat(SqlUtils.COMMA);
            }
            r = r.concat(SqlUtils.QUOTE_DBL).concat(codes[i]).concat(SqlUtils.QUOTE_DBL);
        }
        return r;
    }

    public int getPartnerRank() {
        return partnerRank;
    }

    public boolean isReporterUrlCodeIsDefault() {
        return reporterUrlCodeIsDefault;
    }

    public String getFilterRequestType() {
        return filterRequestType;
    }

    public String getUrlTemplate() {
        return urlTemplate;
    }

    public boolean isLoadTableData() {
        return loadTableData;
    }

    public String getSearchSectionUrlCode() {
        return searchSectionUrlCode;
    }

    public String[] getSearchSectionUrlCodes() {
        return searchSectionUrlCodes;
    }

    public List<Integer> getSearchSectionIds() {
        return searchSectionIds;
    }

    public String getRequestURI() {
        return requestURI;
    }

    
}
